Ext.define('Util.SessionManager', {});

window.SessionManager =
{

    getCurrentUser : function(callback, scope)
    {
        Functions.jsonCommand(Functions.GET, "/", {},
        {
            success : function(response)
            {
                Ext.callback(callback, scope,
                [
                    response
                ]);
            }
        });
    },

    createUserCookie : function(userName, sessionId, callback, scope)
    {
        var user =
        {
            name : userName,
            sessionId : sessionId
        };
        Ext.util.Cookies.set('userSession', Ext.encode(user));
        Ext.callback(callback, scope);
    },

    getRedirectURL : function()
    {
        var redirectURL = window.location.search.substring(1);

        redirectURL = redirectURL.split('redirectURL=');
        redirectURL = redirectURL[1];

        if (redirectURL === null)
        {
            redirectURL = Config.DEFAULT_REDIRECT;
        }

        return redirectURL;
    }
};
